package aries;

/******************************************************************************
 * You may modify, publish, and use Aries for your own purpose. BUT
 * DON'T REMOVE THIS TEXT.
 * Visit my facebook: http://www.facebook.com/freeskies or
 * Follow my twitter: @freeskys
 *
 *
 * Author: Harditya Rahmat Ramadhan
 * Licence: GPLv2
 *****************************************************************************/

import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

public class XML {

    private Element element;
    
    /**
     * Constructor
     * 
     * @param fileName
     * @throws ParserConfigurationException
     * @throws SAXException
     * @throws IOException 
     */
    public XML(String fileName) throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        File file = new File(fileName);
        if (file.exists()) {
            Document doc = db.parse(file);
            this.element = doc.getDocumentElement();
        }
    }
    
    /**
     * Get attribute of the current element.
     * 
     * @param attribute
     * @return String
     */
    public String getAttribute(String attribute) {
        return this.element.getAttribute(attribute);
    }
    
    /**
     * Set attribute of the current element.
     * 
     * @param attribute
     * @param value 
     */
    public void setAttribute(String attribute, String value) {
        this.element.setAttribute(attribute, value);
    }
    
    /**
     * Remove attribute of the current element.
     * 
     * @param attribute 
     */
    public void removeAttribute(String attribute) {
        this.element.removeAttribute(attribute);
    }
    
    /**
     * Get the element.
     * 
     * @return Element
     */
    public Element getElement() {
        return this.element;
    }
    
    /**@TODO : Read and write XML. **/
}
